package net.lzzy.practices;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author admin
 */
@Component
public class PracticesMvcConfigurer implements WebMvcConfigurer {
    @Value("${user.pic}")
    private String picPath;
    @Value("${pic.size}")
    private int maxPicSize;
    @Bean
    public CommonsMultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setMaxUploadSize(maxPicSize);
        return resolver;
    }

    @Override
    public void addResourceHandlers(@SuppressWarnings("null") ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pic/**")
                .addResourceLocations("file:/"+picPath,
                        "classpath:/webapp/",
                        "classpath:/static/",
                        "classpath:/public/");
            //通过配置URL规则和要查找的位置，spring MVC在处理静态资源的请求时，按照指定的路径规则从这些位置查找相应的资源文件，
        // 如果找到相应的资源文件，则返回给客户端，否则继续处理其他请求。
    }
}
